function getRect(context, selector) {
  return new Promise(function (resolve) {
    wx.createSelectorQuery()
      .in(context)
      .select(selector)
      .boundingClientRect()
      .exec(function (rect) {
        if (rect === void 0) {
          rect = [];
        }
        return resolve(rect[0]);
      });
  });
}
Component({
  properties: {
    title: String,
    fixed: {
      type: Boolean,
      observer: 'setHeight',
    },
    placeholder: {
      type: Boolean,
      observer: 'setHeight',
    },
    leftText: String,
    rightText: String,
    customStyle: String,
    leftArrow: Boolean,
    background: String,
    titlePosition: {
      type: String,
      value: 'center'
    },
    titleColor: String,
    background: {
      type: String,
      value: '#ffffff'
    },
    border: {
      type: Boolean,
      value: true,
    },
    zIndex: {
      type: Number,
      value: 1,
    },
    safeAreaInsetTop: {
      type: Boolean,
      value: true,
    },
  },
  data: {
    height: 46,
  },
  lifetimes: {
    attached() {
      var statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
      this.setData({
        statusBarHeight: statusBarHeight,
        height: 46 + statusBarHeight,
      });

      this.setHeight();
    }
  },

  methods: {
    onClickLeft: function () {
      this.triggerEvent('click-left');
    },
    onClickRight: function () {
      this.triggerEvent('click-right');
    },
    setHeight: function () {
      var _this = this;
      if (!this.data.fixed || !this.data.placeholder) {
        return;
      }
      wx.nextTick(function () {
        getRect(_this, '.custom-nav-bar').then(function (res) {
          if (res && 'height' in res) {
            _this.setData({
              height: res.height
            });
          }
        });
      });
    },
  },
});